#!/usr/bin/env python
# -*- coding: utf-8 -*-

""" By Martin Senande-Rivera
    For Towards and atmosphere more favourable to firestorm development in Europe """

import os
import glob, sys
import numpy as np
import xarray as xr
import pandas as pd

year=sys.argv[1]    # Enter year
month=sys.argv[2]   # Enter month

path_dmp='./DMP/GLS/'
path_outs='./DMP/Months/'

# Read files
DMP = xr.open_mfdataset(path_dmp+'c_gls_DMP-RT6_'+year+month+'*.nc',combine='by_coords')['DMP']
DMP.values[DMP.values==-0.02]=np.nan

# DMP mean of each month and crop to region
DMP_mean = DMP.mean(dim='time',skipna=True).sel(lat=slice(80.,10.),lon=slice(-20.,50.))
DMP_mean.to_netcdf(path_outs+'DMP_'+year+'_'+month+'.nc')  # Save output



